#include "Character.h"


Character::Character()
{
	//m_CheckCollision = new Collision();
	m_Gravity = FALLDOWN_VELOCITY_DECREASE;
	m_ToolBullet = NULL;
}
Character::~Character()
{
	delete m_ToolBullet;
}

void Character::Draw(LPD3DXSPRITE SpriteHandler)
{
	if (m_Flip == SpriteEffect::None)
	{
		m_Scale.x = 1.0f;
		m_Scale.y = 1.0f;
	}
	else
	{
		m_Scale.x = -1.0f;
		m_Scale.y = 1.0f;
	}

	if ( m_ToolBullet != NULL)
		m_ToolBullet->Draw(SpriteHandler, m_Vpx);

	CObject::Draw(SpriteHandler);
}

void Character::loadPositionGunAtSprite(char *Path)
{
	ifstream file;
	file.open(Path);

	while (!file.eof())
	{
		int id;
		int direct;
		int x;
		int y;

		file >> id >> direct >> x >> y;

		ObjectTittle temp(id, direct, x, y);
		m_positionShootAtSprite.push_back(temp);
	}

	file.close();
}

void Character::UpdateCollisionMap(vector<ObjectTittle> &NodeTitle)
{
	m_Gametime->setTime();
	if (m_Gametime->getElapsedTimePerSecond() >= m_TimeAnimation)
	{
		m_IsCollision = false;

		if (m_Status == IDStatus::JUMP_UP) return;

		for (int i = 0; i < NodeTitle.size(); i++)
		{
			if (NodeTitle[i].m_Id == ID_Move_On_MAP || NodeTitle[i].m_Id == ID_Move_Under_Water)
			{
				m_CheckCollision->Init(m_Box, Box(NodeTitle[i].m_X, NodeTitle[i].m_Y, NodeTitle[i].m_Width, NodeTitle[i].m_Height));

				if (m_CheckCollision->isCollision() == DIR::TOP)
				{
					m_Gravity = m_CheckCollision->getVeclocity_vy();
					m_Status = IDStatus::STAND;
					m_IsCollision = true;

					if (NodeTitle[i].m_Id == ID_Move_Under_Water)
						m_TypeMove = TypeMove::Move_UnderWater;
					else
						m_TypeMove = TypeMove::Move_OnTheLand;

					break;
				}
			}
		}
	}
}
void Character::setGun(IDGun gun)
{
	m_ToolBullet->setGun(gun);
}
